/**
 * author: wancheng
 * date: 2018/08/31
 * des: 流程管理
 *
 */

import {
  findTask
} from './api.js'




export const userListsetting = [{
  field: 'procDefName',
  title: '流程定义名称',
  type: 'text',
  searchable: true
},
{
  field: 'taskName',
  title: '任务节点',
  type: 'text',

},
{
  field: 'userName',
  title: '用户号/员工号',
  type: 'user'
},
{
  field: 'employeeName',
  title: '用户姓名',
  type: 'text'
}

]


/**
 * 用户列表的set
 * userListsetting,roleListsetting,orgListsetting  followListsetting
 */


export const userAddsetting = [{
  field: 'procDefId',
  title: '流程定义名称',
  type: 'select-all-url',
  url: '/acttaskmanages/findAllFlow',
  searchable: true,
  formChange: (form, thisSetting, allSetting) => {
    allSetting.forEach(v => {
      const id = form.procDefId
      const options = []
      const params = {
        procDefId: id
      }
      findTask(params).then((response) => { // 根据部门查询岗位
        if (response.data !== undefined) {
          if (response.success) {
            // console.log(response.data)
            response.data.forEach((v, index) => {
              const obj = {
                value: v.id,
                name: v.name
              }
              options.push(obj)
            })
            allSetting.forEach(v => {
              if (v.field === 'taskKey') {
                v.options = options
              }
            })
          }
        }
      })
    })
  }
},
{
  field: 'taskKey',
  info: '任务节点KEY依赖于流程定义',
  title: '任务节点KEY',
  type: 'selected',
  options: []
},
{
  field: 'userId',
  title: '用户ID',
  isUser: true,
  type: 'user-tree'
}

]



export const userEditsetting = [{
  field: 'procDefId',
  title: '流程定义名称',
  type: 'select-all-url',
  url: '/acttaskmanages/findAllFlow',
  searchable: true,
  disableEdit: true,
  formChange: (form, thisSetting, allSetting) => {
    allSetting.forEach(v => {
      const id = form.procDefId
      const options = []
      const params = {
        procDefId: id
      }
      findTask(params).then((response) => { // 根据部门查询岗位
        if (response.data !== undefined) {
          if (response.success) {
            // console.log(response.data)
            response.data.forEach((v, index) => {
              const obj = {
                value: v.id,
                name: v.name
              }
              options.push(obj)
            })
            allSetting.forEach(v => {
              if (v.field === 'taskKey') {
                v.options = options
              }
            })
          }
        }
      })
    })
  }
},
{
  field: 'taskKey',
  info: '任务节点KEY依赖于流程定义',
  title: '任务节点KEY',
  type: 'selected',
  disableEdit: true,
  options: []
},
{
  field: 'userId',
  title: '用户ID',
  isUser: true,
  type: 'user-tree'
}

]

/**
 * 角色
 */
export const roleListsetting = [{
  field: 'procDefName',
  title: '流程定义名称',
  type: 'text',
  searchable: true,
},
{
  field: 'taskName',
  title: '任务节点',
  type: 'text',

},
{
  field: 'roleName',
  title: '角色',
  url: 'text',
  hideEdit: true,
  hideDetail: true
}
]


export const roleDetailsetting = [{
  field: 'procDefName',
  title: '流程定义名称',
  type: 'text',
  searchable: true,
},
{
  field: 'taskName',
  title: '任务节点',
  type: 'text',

},
{
  field: 'roleId',
  title: '角色',
  type: 'checkbox-role',
  isHiden: true
}
]

export const roleAddsetting = [{
  field: 'procDefId',
  title: '流程定义名称',
  type: 'select-all-url',
  url: '/acttaskmanages/findAllFlow',
  formChange: (form, thisSetting, allSetting) => {
    allSetting.forEach(v => {
      const id = form.procDefId
      const options = []
      const params = {
        procDefId: id
      }
      findTask(params).then((response) => { // 根据部门查询岗位
        if (response.data !== undefined) {
          if (response.success) {
            // console.log(response.data)
            response.data.forEach((v, index) => {
              const obj = {
                value: v.id,
                name: v.name
              }
              options.push(obj)
            })
            allSetting.forEach(v => {
              if (v.field === 'taskKey') {
                v.options = options
              }
            })
          }
        }
      })
    })
  }
},
{
  field: 'taskKey',
  title: '任务节点KEY',
  info: '任务节点KEY依赖于流程定义',
  type: 'selected',
  options: []
}, {
  field: 'roleId',
  title: '角色',
  url: 'url',
  type: 'checkbox-role'
}
]







export const roleEditsetting = [{
  field: 'procDefId',
  title: '流程定义名称',
  type: 'select-all-url',
  url: '/acttaskmanages/findAllFlow',
  disableEdit: true,
  formChange: (form, thisSetting, allSetting) => {
    allSetting.forEach(v => {
      const id = form.procDefId
      const options = []
      const params = {
        procDefId: id
      }
      findTask(params).then((response) => { // 根据部门查询岗位
        if (response.data !== undefined) {
          if (response.success) {
            // console.log(response.data)
            response.data.forEach((v, index) => {
              const obj = {
                value: v.id,
                name: v.name
              }
              options.push(obj)
            })
            allSetting.forEach(v => {
              if (v.field === 'taskKey') {
                v.options = options
              }
            })
          }
        }
      })
    })
  }
},
{
  field: 'taskKey',
  title: '任务节点KEY',
  info: '任务节点KEY依赖于流程定义',
  type: 'selected',
  disableEdit: true,
  options: []
}, {
  field: 'roleId',
  title: '角色',
  url: 'url',
  type: 'checkbox-role'
}
]

/**
 * 部门
 */
export const orgListsetting = [{
  field: 'procDefName',
  title: '流程定义名称',
  type: 'text',
  searchable: true,
},
{
  field: 'taskName',
  title: '任务节点',
  type: 'text',

},
{
  field: 'orgId',
  title: '部门',
  type: 'org',
  changeOnSelect: true,
  isHiden: true
},
{
  field: 'orgName',
  title: '部门',
  type: 'org',
  hideEdit: true,
  hideDetail: true
},

{
  field: 'orgScope',
  title: '机构范围',
  type: 'radio',
  customText: (item) => {
    switch (item.orgScope) {
      case '1':
        return '本部门'
      case '2':
        return '该部门及子部门'
    }
  },
  optional: [{
    name: '本部门',
    value: '1'
  },
  {
    name: '该部门及子部门',
    value: '2'
  }

  ]
}

]



export const orgAddsetting = [{
  field: 'procDefId',
  title: '流程定义名称',
  type: 'select-all-url',
  url: '/acttaskmanages/findAllFlow',
  formChange: (form, thisSetting, allSetting) => {
    allSetting.forEach(v => {
      const id = form.procDefId
      const options = []
      const params = {
        procDefId: id
      }
      findTask(params).then((response) => { // 根据部门查询岗位
        if (response.data !== undefined) {
          if (response.success) {
            // console.log(response.data)
            response.data.forEach((v, index) => {
              const obj = {
                value: v.id,
                name: v.name
              }
              options.push(obj)
            })
            allSetting.forEach(v => {
              if (v.field === 'taskKey') {
                v.options = options
              }
            })
          }
        }
      })
    })
  }
},
{
  field: 'taskKey',
  title: '任务节点KEY',
  info: '任务节点KEY依赖于流程定义',
  type: 'selected',
  options: []
}, {
  field: 'orgId',
  title: '部门',
  type: 'org',
  changeOnSelect: true,
  isHide: true
},
{
  field: 'orgName',
  title: '部门',
  type: 'org',
  hideEdit: true,
  hideDetail: true
},

{
  field: 'orgScope',
  title: '机构范围',
  type: 'radio',
  optional: [{
    name: '本部门',
    value: '1'
  },
  {
    name: '该部门及子部门',
    value: '2'
  }

  ]
}

]



export const orgEditsetting = [{
  field: 'procDefId',
  title: '流程定义名称',
  type: 'select-all-url',
  disableEdit: true,
  url: '/acttaskmanages/findAllFlow',
  formChange: (form, thisSetting, allSetting) => {
    allSetting.forEach(v => {
      const id = form.procDefId
      const options = []
      const params = {
        procDefId: id
      }
      findTask(params).then((response) => { // 根据部门查询岗位
        if (response.data !== undefined) {
          if (response.success) {
            // console.log(response.data)
            response.data.forEach((v, index) => {
              const obj = {
                value: v.id,
                name: v.name
              }
              options.push(obj)
            })
            allSetting.forEach(v => {
              if (v.field === 'taskKey') {
                v.options = options
              }
            })
          }
        }
      })
    })
  }
},
{
  field: 'taskKey',
  title: '任务节点KEY',
  info: '任务节点KEY依赖于流程定义',
  type: 'selected',
  disableEdit: true,
  options: []
}, {
  field: 'orgId',
  title: '部门',
  type: 'org',
  disableEdit: true,
  changeOnSelect: true,
  isHide: true
},
{
  field: 'orgName',
  title: '部门',
  type: 'org',
  hideEdit: true,
  hideDetail: true
},

{
  field: 'orgScope',
  title: '机构范围',
  type: 'radio',
  optional: [{
    name: '本部门',
    value: '1'
  },
  {
    name: '该部门及子部门',
    value: '2'
  }

  ]
}

]



/**
 * 流程
 */
export const followListsetting = [
  {
    field: 'procDefName',
    title: '流程定义名称',
    type: 'text',
    searchable: true,
  },

  {
    field: 'srcTaskName',
    title: '原任务节点',
    type: 'text',
    searchable: true,
    disableEdit: true
  }, {
    field: 'destTaskName',
    title: '目标任务节点',
    type: 'text',
    disableEdit: true
  },
  {
    field: 'action',
    title: '操作',
    type: 'radio',
    disableEdit: true,
    customText: (item) => {
      switch (item.action) {
        case 1:
          return '通过'
        case 0:
          return '不通过'
      }
    },
    optional: [{
      name: '通过',
      value: 1
    },
    {
      name: '不通过',
      value: 0
    }
    ]
  },

  {
    field: 'status',
    title: '状态',
    type: 'radio',
    customText: (item) => {
      switch (item.status) {
        case '1':
          return '启用'
        case '0':
          return '禁用'
      }
    },
    optional: [{
      name: '启用',
      value: '1'
    },
    {
      name: '禁用',
      value: '0'
    }
    ]
  },
  {
    field: 'seqno',
    title: '排序',
    type: 'text'
  }
]
